Release 10.1A: OpenEdge Development:
Progress Dynamics Basic Development
Error message checking include file (checkerr.i)
The include file
aferrortxt.itakes care of formatting messages into a standard format in preparation for returning them to the client to be presented to the user. As the examples above show, simply returning the message text string from any of the standard validation procedures results in the errors being processed correctly. The wrapper code that runs the validation procedures handles the messages for you.In other cases, however, you might need to process errors yourself (for example, from stand-alone business logic procedures that you write, as described later). There is another standard include file, called
checkerr.i, that you should always use when checking for errors within your own logic procedure, instead of doing anIFERROR-STATUS:ERRORcheck manually.The include file handles the checking of the error status. If an error occurred, it handles displaying of the error message or passing on of the error message and return value back to the caller. It also contains code to build a return value from the Progress Dynamics get-message method if the
RETURN-VALUEis empty. This is a very flexible include file and should cater for all scenarios. Table 10–2 lists the named arguments.
The
&define-onlyargument is therefore useful ifcheckerr.iis included more than once in the same file but separate procedures. If you place this code at the top of your file, the necessary variables will be defined once, and no other action will take place, as shown:
When you are using
checkerr.iin server-side business logic, normally some combination of the arguments in Table 10–2 that handle theRETURNstatement are the ones you will use in your code. If you are displaying an error message in client code fromcheckerr.i, then arguments listed in Table 10–3 are also additionally available.
Table 10–4 lists the arguments available if the message type is
QUEforQuestion.
Table 10–4: Question arguments Argument Description Data type, the default isCharacter. Format of question, the default is 'CHR(35). Default answer, the default is empty.Note: For a question message type, the defaults change to
&message-buttons = 'OK,CANCEL',&button-default = 'OK',&button-cancel = 'CANCEL'.The following rules apply when you use the
checkerr.iinclude file:
- Required logical arguments must be passed unquoted as
YESorNO. Other text arguments must be single quoted literals (for example,'text'or unquoted variables), and if the literals require spaces, they should be double-quoted then single-quoted (for example,"'text'").- All arguments can be left blank, in which case the error will not be displayed and will be passed on with a return error.
- If everything is left blank except
display-errorisYES, then the error will be displayed using the Progress Dynamics message dialog box and a standard return statement done.- If in a transaction, the error will be passed on regardless, unless {&no-return} is set to
YES.- If display error is set to
YES, the default is to do a return only rather than return error.- If display error is set to
NO, the default is to do a return error to pass the error on.- If return-only is set to
YES, this will override any other return settings and let you regain control.Following the include file, if
{&no-return}is set toYES. Table 10–5 lists the variable values available.
Table 10–5: NO-RETURN variables Variable ValueCHR(3)-delimited list of error messages. Button pressed. Answer if question dialog box is used.
Here are a few examples of using the
checkerr.iinclude file. First, another standard Progress Dynamics include reference is required in every procedure that uses other Progress Dynamics includes, such ascheckerr.i. This isafglobals.i, which defines global references to some of the Progress Dynamics managers.This example runs a business logic procedure using the
launch.imechanism (described in more detail in Chapter 11 "Building Advanced Business Logic in a Progress Dynamics Application"). It then usescheckerr.iupon return to intercept any errors that occur. For the sake of simplicity, the first example simply displays the error, using the standard Progress Dynamics message dialog box, so that you can see how that works, even though you would, of course, not invoke this display directly from a server-side logic procedure.Here is the code that launches the procedure and a reference to
checkerr.ito display an error, if there is one. Pass in the name of the external procedure to run persistent on the server, the name of the internal procedure to run in its handle, whether to invoke it on the AppServer, and a list of parameters to it. The internal procedurevalidateDatasetQueryusesaferrortxt.ito return error numberAF:114if there is an error in the names of the input parameters. It is this error that you intercept here, as shown:
If you modify the parameter list to the
validateDatasetQueryprocedure so that it is no longer valid, an error message is generated and picked up bycheckerr.i:
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |